package com.vishop.models;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Winkelwagen {

	private Collection<Product> producten;
	private double prijs;
	private double korting;
	private double btw;
	
	public Winkelwagen()
	{
		producten = new  ArrayList<Product>();
		btw = 1.19;
	}	
	
	public Collection<Product> getProducten() {
		return producten;
	}

	public void setProducten(Collection<Product> producten) {
		this.producten = producten;
	}

	public void setPrijs(double prijs) {
		this.prijs = prijs;
	}

	public double getPrijs() 
	{
		prijs = 0;
		for(Product product: producten)
		{
			prijs += product.getPrijs();
		}
		if(prijs > korting) { prijs -= korting; }
		
		return prijs * this.btw;
	}
	
	public void setKorting(double korting) {
		this.korting = korting;
	}
	
	public void removeProduct(Long id)
	{
		Iterator<Product> iterator = producten.iterator();
		
		while(iterator.hasNext())
		{
			if(iterator.next().getProductId() == id.intValue()){ iterator.remove();} 
		}
	}
	
}
